from PySide2 import QtCore
from PySide2.QtWidgets import *
import sys

class Demo(QWidget):
    def __init__(self, parent=None):
        super(Demo, self).__init__(parent)
        self.initUI()

    def initUI(self):
        grid = QGridLayout()
        label1 = QLabel()
        label1.setText("用户名：")
        text1 = QLineEdit()
        label2 = QLabel()
        label2.setText("密码：")
        text2 = QLineEdit()
        btn1 = QPushButton()
        btn1.setText("登录")
        btn2 = QPushButton()
        btn2.setText("取消")
        #
        grid.addWidget(label1, 0, 0, QtCore.Qt.AlignLeft)
        grid.addWidget(text1, 0, 1, QtCore.Qt.AlignLeft)
        grid.addWidget(label2, 1, 0, QtCore.Qt.AlignLeft)
        grid.addWidget(text2, 1, 1, QtCore.Qt.AlignLeft)
        grid.addWidget(btn1, 2, 0, QtCore.Qt.AlignCenter)
        grid.addWidget(btn2, 2, 1, QtCore.Qt.AlignCenter)
        self.setLayout(grid)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    demo = Demo()
    demo.show()
    sys.exit(app.exec_())
